#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    PluginManager::instance()->loadAllPlugins();
    qDebug()<<"allPluginsName: "<<PluginManager::instance()->allPluginsName();

    QPluginLoader *loader1 = PluginManager::instance()->getPlugin("pluginA");
    if(loader1) {
        PluginInterface *pluginA = dynamic_cast<PluginInterface*>(loader1->instance());
        if(pluginA) {
            PluginMetaData m;
            m.dest = "pluginB";
            m.from = "pluginA";
            m.msg = "插件A发给插件B的消息";
            pluginA->sendMsgToManager(m);
        }
    }

    QPluginLoader *loader2 = PluginManager::instance()->getPlugin("pluginB");
    if(loader2) {
        PluginInterface *pluginB = dynamic_cast<PluginInterface*>(loader2->instance());
        if(pluginB) {
            PluginMetaData m;
            m.dest = "pluginA";
            m.from = "pluginB";
            m.msg = "插件B发给插件A的消息";
            pluginB->sendMsgToManager(m);
        }
    }

}

MainWindow::~MainWindow()
{
    delete ui;
}

